﻿Ext.require([
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.tab.*',
    'Ext.window.*',
    'Ext.tip.*',
    'Ext.layout.container.Border'
    ]);

Ext.onReady(function () {

    Ext.define('Status', {
        extend: 'Ext.data.Model',
        fields: [
	           { name: 'Id', type: 'int' },
	           { name: 'Name', type: 'string' },
               { name: 'Conclusive', type: 'string' },
               { name: 'Shown', type: 'string' },
               { name: 'Dependency', type: 'string' }               
	        ],
        idProperty: 'Id'
    });
    

    var dsCall = Ext.create('Ext.data.Store', {
        autoLoad: true,
        autoSync: true,
        model: 'Status',
        storeId: 'Id',
        proxy: {
            type: 'rest',
            url: '../Status/GetAll',
            reader: {
                type: 'json',
                root: 'statuses'
            },
            writer: {
                type: 'json'
            }
        }
    });

    var grid = Ext.create('Ext.grid.Panel', {
        store: dsCall,
        stateful: true,
        collapsible: true,
        multiSelect: true,
        stateId: 'stateGrid',
        fit: true,
        columns: [
            {
                text: 'Código',
                flex: 0,
                sortable: true,
                width: 80,
                dataIndex: 'Id'
            },
            {
                text: 'Nome',
                sortable: true,
                width: 400,
                dataIndex: 'Name'
            },
            {
                text: 'Conclusivo',
                sortable: true,
                dataIndex: 'Conclusive'
            },
            {
                text: 'Dependência',
                sortable: true,
                dataIndex: 'Dependency'
            },
            {
                text: 'Mostrar para',
                sortable: true,
                dataIndex: 'Shown'
            },
            {
                text: 'Excluir',
                width: 60,
                renderer: function (val) { return '<input id="show-btn" type="image" src="../../Content/Themes/Aliasis/delete.gif" value="Pré-Visualizar" onClick="deleteStatusWindow(' + val + ');"/>'; },
                align: 'center',
                dataIndex: 'Id'
            }
        ],
        height: 350,
        width: "100%",
        title: 'Status',
        renderTo: 'grid-status',

        dockedItems: [{
            xtype: 'toolbar',
            items: [{
                text: 'Criar status',
                iconCls: 'iconAdd',
                handler: function () {
                    window.location = "Status/Create";
                }
            }]
        }],

        viewConfig: {
            stripeRows: true,
            enableTextSelection: true
        }
    });

});